package com.wyzz.hr.action;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpSession;

import com.wyzz.hr.base.DWRUtil;
import com.wyzz.hr.base.wf.leaverequest.LrWfApproverAction;
import com.wyzz.hr.bo.ILeaverequestBO;
import com.wyzz.hr.bo.ILeavetypeBO;
import com.wyzz.hr.bo.impl.ExaminDateUtil;
import com.wyzz.hr.pojo.Employee;
import com.wyzz.hr.pojo.Leaverequest;
import com.wyzz.hr.pojo.Leavetype;
import com.wyzz.hr.util.MyTools;
import com.wyzz.hr.vo.APM;
import com.wyzz.hr.vo.LeaveBalanceLR;

public class LeavebalanceBaseAction extends LrWfApproverAction {

	public LeavebalanceBaseAction() {
	}

	public List getEmpLRList(String empid, int year, HttpSession session) {
		if (!DWRUtil.checkAuth("leavebalanceManage", "execute").equals("HR"))
			return null;
		ILeaverequestBO lr_BO = (ILeaverequestBO) getBean("leaverequestBO");
		Calendar start = Calendar.getInstance();
		Calendar end = Calendar.getInstance();
		start.set(year, 0, 1, 0, 0, 0);
		start.set(14, 0);
		end.set(year, 11, 31, 23, 59, 59);
		end.set(14, 0);
		List retur = new LinkedList();
		ILeavetypeBO lt_BO = (ILeavetypeBO) getBean("leavetypeBO");
		Leavetype lt = lt_BO.getAnnualLeave();
		Integer statusSet[] = null;
		List lrset = lr_BO.getTotalStatusSetList(new Employee(empid), start
				.getTime(), end.getTime(), lt, statusSet);
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd ");
		double hoursPerDay = ExaminDateUtil.getDefaultHoursPerDay();
		for (int j = 0; j < lrset.size(); j++)
			retur.add(new LeaveBalanceLR(((Leaverequest) lrset.get(j))
					.getLrNo().toString(), (new StringBuilder()).append(
					df.format(((Leaverequest) lrset.get(j)).getLrStartDate()))
					.append(
							APM.getDescription(((Leaverequest) lrset.get(j))
									.getLrStartDate())).toString(),
					(new StringBuilder()).append(
							df.format(((Leaverequest) lrset.get(j))
									.getLrEndDate())).append(
							APM.getDescription(((Leaverequest) lrset.get(j))
									.getLrEndDate())).toString(), MyTools
							.round(((Leaverequest) lrset.get(j))
									.getLrTotalHours().doubleValue()
									/ hoursPerDay, 2), ((Leaverequest) lrset
							.get(j)).getLrStatusMean()));

		return retur;
	}

	public double getLBLRCanUsedDays(double hoursBefore, double hoursAfter) {
		double total = hoursBefore + hoursAfter;
		double hoursPerDay = ExaminDateUtil.getDefaultHoursPerDay();
		total = MyTools.round(total / hoursPerDay, 2);
		return total;
	}

	private static final long serialVersionUID = 0x105385ad16941ddeL;
}
